package com.example.kaogong.common.handler;

import com.example.kaogong.common.exception.NotExistException;
import com.example.kaogong.common.exception.ParamsErrorException;
import com.example.kaogong.common.exception.TokenErrorException;
import com.example.kaogong.common.utils.RespBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * @author luojun
 * @version 1.0
 * @date 2022/2/28 21:12
 * 系统全局异常处理
 */
@Slf4j
@RestControllerAdvice
public class SysExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    public RespBean exceptionHandler(Exception e){
        log.error(e.getMessage());
        return RespBean.error("系统出现异常");
    }

    @ExceptionHandler(value = NotExistException.class)
    public RespBean notExistExceptionHandler(NotExistException e) {
        log.error(e.getMessage());
        return RespBean.error(e.getMessage());
    }

    @ExceptionHandler(value = TokenErrorException.class)
    public RespBean tokenErrorExceptionHandler(TokenErrorException e) {
        log.error(e.getMessage());
        return RespBean.error(e.getMessage());
    }

    @ExceptionHandler(value = ParamsErrorException.class)
    public RespBean paramsErrorExceptionHandler(ParamsErrorException e) {
        log.error(e.getMessage());
        return RespBean.error(e.getMessage());
    }
}
